package com.cyx.netty.gateway.client.channel;

import com.cyx.netty.gateway.support.ServerWebExchange;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.handler.codec.http.HttpClientCodec;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.timeout.IdleStateHandler;
import java.util.concurrent.TimeUnit;

public class ProxyClientChannelInitializer extends ChannelInitializer {

    private ServerWebExchange serverWebExchange;

    public ProxyClientChannelInitializer(ServerWebExchange serverWebExchange) {
        this.serverWebExchange = serverWebExchange;
    }

    @Override
    protected void initChannel(Channel channel) {
        channel.pipeline().addLast(new HttpClientCodec());
        channel.pipeline().addLast(new HttpObjectAggregator(1048576*2));
        channel.pipeline().addLast(new ProxyClientChannelInboundHandlerAdapter(serverWebExchange));
        channel.pipeline().addLast(new HeartBeatClientHandler(serverWebExchange));
        channel.pipeline().addLast(new IdleStateHandler(58, 0, 0, TimeUnit.SECONDS));
    }


}
